;(function(){

    var init = function($){
        $(function(){
            var token = JSON.parse(localStorage.getItem("hngz_token"));

            //全局的ajax访问，处理ajax清求时异常
            $.ajaxSetup({
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                cache: false,
                xhrFields: {
                    withCredentials: true
                },
                beforeSend: function (ajax,XMLHttpRequest) {
                    if(XMLHttpRequest.url && XMLHttpRequest.url.indexOf('http') === 0){
                        return;
                    }
                    var baseUrl = "http://localhost:8023/";
                    XMLHttpRequest.url = baseUrl + XMLHttpRequest.url;
                },
                complete: function (XMLHttpRequest, textStatus) {
                    //通过XMLHttpRequest取得响应结果
                    var res = XMLHttpRequest.responseText;
                    try {
                        if (res) {
                            res = JSON.parse(res);
                            if (res.status == -4) {
                                window.open('login.html', '_top');
                            }
                        } else {
                        }
                    } catch (e) {
                    }
                }
            });
            if (token && token.access_token) {
                $.ajaxSetup({
                    headers: {
                        "Authorization": 'Bearer ' + token.access_token
                    }
                });
            }
        });
    };


    if(typeof define !== 'undefined'&&define.amd) {
        define(['jquery'],init);
    }else{
        init($);
    }
})();